package com.isnmp.common.snmp.impl;

import java.util.Vector;

import net.percederberg.mibble.MibValueSymbol;
import net.percederberg.mibble.snmp.SnmpObjectType;

import org.snmp4j.PDU;
import org.snmp4j.Snmp;
import org.snmp4j.Target;
import org.snmp4j.event.ResponseEvent;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.Variable;
import org.snmp4j.smi.VariableBinding;

import com.isnmp.common.base.MyException;

public class UpdateAction {
    public static void update(Object paramObject, Snmp paramSnmp, Target paramTarget) throws MyException {
        try {
            String str1 = SNMPUtils.getMibOIDofClass(paramObject.getClass());
            Object localObject = SNMPAPIImpl.getInstance().getMibSymbolByOid(str1);
            String str2 = SNMPUtils.getTableOrGroupIndexOID(paramObject, (MibValueSymbol) localObject);
            Class localClass = paramObject.getClass();
            Vector localVector = SNMPUtils.getWritedFieldsInMibNode(localClass, (MibValueSymbol) localObject);
            PDU localPDU = new PDU();
            for (int i = 0; i < localVector.size(); i++) {
                MibValueSymbol localMibValueSymbol = (MibValueSymbol) localVector.get(i);
                String str3 = localMibValueSymbol.getValue().toString();
                String str4 = str3 + "." + str2;
                String str5 = ((MibValueSymbol) localObject).getMib().getSymbolByOid(str3).getName();
                SnmpObjectType localSnmpObjectType = (SnmpObjectType) localMibValueSymbol.getType();
                Variable localVariable = SNMPUtils.getFieldValue(paramObject, str5, localSnmpObjectType.getSyntax());
                localPDU.add(new VariableBinding(new OID(str4), (Variable) localVariable));
            }
            ResponseEvent localResponseEvent = paramSnmp.set(localPDU, paramTarget);
            SNMPUtils.checkSNMPErro(localResponseEvent);
        } catch (Exception localException) {
            Object localObject = Messages.getString("UpdateAction.1") + paramObject.getClass().getName() + Messages.getString("UpdateAction.2") + paramTarget.getAddress() + Messages.getString("UpdateAction.3") + localException.getMessage();
            throw new MyException((String) localObject);
        }
    }
}